<template>
  <el-container class="home-container">
    <el-header class="">
      <img src="../assets/logo.png" alt="">
      <span>电商后台管理系统</span>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!--左侧-->
      <el-aside :width="isCollapse?'60px':'200px'">
        <el-menu
          unique-opened
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
          :collapse-transition="false" router>
          <div class="toggle-btn" @click="toggleCollapse">|||</div>
          <el-submenu :index="item.id+''" v-for="item in menuLists" :key="item.id">
            <template slot="title">
              <i :class="menuIcons[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--主内容区-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import {getMenuList} from '../network/home'

  export default {
    name: "Home",
    data() {
      return {
        menuLists: [],
        menuIcons: {
          '125': 'el-icon-user-solid',
          '103': 'el-icon-aim',
          '101': 'el-icon-coin',
          '102': 'el-icon-s-order',
          '145': 'el-icon-data-line',
        },
        isCollapse: false
      }
    },
    created() {
      this.getMenuList()
    },
    methods: {
      logout() {
        window.sessionStorage.clear();
        this.$message.success('退出成功')
        this.$router.push('/login')
      },
      getMenuList() {
        getMenuList().then(res => {
          console.log(res);
          this.menuLists = res.data
        })
      },
      toggleCollapse() {
        this.isCollapse = !this.isCollapse;
      }
    }
  }
</script>

<style lang="less" scoped>
  .home-container {
    height: 100%;
  }

  .el-header {
    background-color: #ee9900;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    font-size: 20px;
    img {
      height: 100%;
    }
  }

  .el-aside {
    background-color: #9a6e3a;
  }

  .el-main {
    background-color: #fffdef;
  }

  .toggle-btn {
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
